<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){
            var app=new Vue({
                el: '#app',
                data: {
                    username:'',
                    age:'',
                    message: 'Hello Vue.js!',
                    tables: [
                        { name: '林贤思',age: '1',time:new Date() },
                        { name: 'lxs',age: '4',time:new Date() },

                    ]
                },
                filters:{
                    himmss:function(v){
                        return(v.getHours()+':'+v.getMinutes()+':'+v.getSeconds())
                    },
                    done:function(value){
                        if(!value) return''
                        value=value.value.toString()
                        return value.charAt(0).toUpperCase()+value.slice(1)
                    }},
                methods: {
//                    reverseMessage: function () {
//                        this.message = this.message.split('').reverse().join('')
//                    },
                    addpople:function(){
                        var s={name:this.username,age:this.age,time:new Date()}
                        this.tables.push(s)
                    },
                    removeall:function(){
                        //var s={name:this.username,age:this.age}
                        this.tables=[]
                    },
                    remove:function(index){
                        this.tables.splice(index,1)
                    }
                }
            })
        }
    </script>
</head>
<body>
<div id="app">
    <p>{{ message }}</p>
    <input v-model="username"></br>

    <input v-model="age"></br>
    <button v-on:click="addpople">添加</button>
    <button v-on:click="removeall">删除所有</button>
    <table border="1">
        <tr>
            <th>序号</th>
            <th>名字</th>
            <th>年龄</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        <tr v-for="(table,index) in tables">
            <td>{{index+1}}</td>
            <td>{{table.time|done}}</td>
            <td>{{table.age}}</td>
            <td>{{table.time|himmss}}</td>
            <td> <button v-on:click="remove(index)">删除</button></td>
        </tr>
    </table>
</div>
</body>
</html>